﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using XcoAppSpaces.Core;
using XcoAppSpaces.Core.Ports;
using System.Threading;

namespace test.XcoAppSpaces.Core
{
	[TestFixture]
	public class testMultiInheritance
	{
		
		abstract class WorkerContract : PortSet<string, int, long>
		{
			public long LongMsg;

			[XcoConcurrent]
			public void ProcessMsg(long msg)
			{
				LongMsg = msg;
				Console.WriteLine("Msg \"" + msg + "\" received!");
			}
		}

		class WorkerInherit1 : WorkerContract
		{
			public string StrMsg;

			[XcoConcurrent]
			public void ProcessMsg(string msg)
			{
				StrMsg = msg;
				Console.WriteLine("Msg \"" + msg + "\" received!");
			}
		}

		class WorkerInherit2 : WorkerInherit1
		{
			public int IntMsg;
			
			[XcoConcurrent]
			public void ProcessMsg(int msg)
			{
				IntMsg = msg;
				Console.WriteLine("Msg \"" + msg + "\" received!");
			}
		}

		[Test]
		public void TestFuncMsg()
		{
			using (XcoAppSpace space = new XcoAppSpace())
			{
				//WorkerInherit2 worker = new WorkerInherit2();
				//space.RunWorker<(worker);
				var worker = (WorkerInherit2)space.RunWorker<WorkerInherit1, WorkerInherit2>();

				worker.Post(123);
				worker.Post((long)456);
				worker.Post("test");

				Thread.Sleep(100);

				Assert.AreEqual((long)456, worker.LongMsg);
				Assert.AreEqual(123, worker.IntMsg);
				Assert.AreEqual("test", worker.StrMsg);
			}
		}
	}
}
